using System;
using NHibernate;
using NHibernate.Criterion;
using RMH.Entities;

namespace RMH.DataAccess
{
    public interface IStaffRepository : IRepository<Staff>
    {
        Staff GetByUserName(string userName);
    }
    public class StaffRepository : RepositoryBase<Staff>, IStaffRepository
    {
        public StaffRepository(ISession session)
            : base(session)
        {
        }

        public Staff GetByUserName(string userName)
        {
            var criteria = base.getCriteria();
            criteria.Add(Expression.Eq("UserName", userName));            
                return criteria.UniqueResult<Staff>();
        }
    }

    public interface IStaffRoleRepository : IRepository<StaffRole>
    {
        StaffRole GetByName(string role);
    }

    public class StaffRoleRepository : RepositoryBase<StaffRole>, IStaffRoleRepository
    {
        public StaffRoleRepository(ISession session)
            : base(session)
        {
        }

        public StaffRole GetByName(string role)
        {
            return base.getCriteria()
                .Add(Expression.Eq("Name", role))
                .UniqueResult<StaffRole>();
        }
    }
}